package com.huika.dealontop.views.common;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.huika.dealontop.R;

public class CommonLoadingView extends RelativeLayout {
    private ImageView loadIv;
    private TextView loadTv;

    public CommonLoadingView(Context context) {
        super(context);
    }

    public CommonLoadingView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void startLoading() {
        if (loadIv == null) {
            loadIv = (ImageView) findViewById(R.id.loadingImageView);
        }
        AnimationDrawable animationDrawable = (AnimationDrawable) loadIv
                .getBackground();
        animationDrawable.start();
    }


    public void stopLoading() {
        loadIv.clearAnimation();
    }

    public void setMessage(String str) {
        if (loadTv == null) {
            loadTv = (TextView) findViewById(R.id.tv_progress);
        }
        loadTv.setText(str);
    }
}
